Skip to content

fix: prevent null crash on entityName.trim() with type check - #34

Open
memosr wants to merge 1 commit into
circlefin:masterfrom
memosr:fix/entityname-null-crash
Open

fix: prevent null crash on entityName.trim() with type check#34
memosr wants to merge 1 commit into
circlefin:masterfrom
memosr:fix/entityname-null-crash

Conversation

@memosr

@memosr memosr commented May 4, 2026

Copy link
Copy Markdown

Problem

In app/api/wallet-set/route.ts, if entityName is missing from the request body, .trim() throws a TypeError before validation can run:

const { entityName } = await req.json();

if (!entityName.trim()) {  // 💥 TypeError if entityName is undefined
  return NextResponse.json({ error: "entityName is required" }, { status: 400 });
}

This causes an unhandled 500 instead of returning a proper 400 response.

Fix

Added a type check before calling .trim():

- if (!entityName.trim()) {
+ if (typeof entityName !== "string" || !entityName.trim()) {
    return NextResponse.json(
-     { error: "entityName is required" },
+     { error: "entityName is required and must be a non-empty string" },
      { status: 400 }
    );
  }

The typeof check safely handles undefined, null, numbers, and any other non-string value before .trim() is ever called.

Impact

  • Correctness: Returns proper 400 instead of unhandled 500
  • Risk: Low — additive validation, no breaking changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant